try {
<% form_selector ||= element_form_id(action: :update, id: @record&.id || params[:id]) %>
var action_link = ActiveScaffold.find_action_link('<%= form_selector %>');
if (action_link) action_link.update_flash_messages('<%= escape_javascript(render('messages')) %>');
<% if successful? %>
  <% if params[:dont_close] %>
    <% row_selector = element_row_id(action: :list, id: @record.id) %>
    ActiveScaffold.update_row('<%= row_selector %>', '<%= escape_javascript(render(list_record_view, record: @record)) %>');
    if (action_link) action_link.target = jQuery('#<%= row_selector %>');
    <%= render 'update_calculations' %>
    <% if params[:iframe] == 'true' %>
      ActiveScaffold.enable_form('<%= form_selector %>');
    <% end %>
  <% else %>
    <% if render_parent? %>
      <% if nested_singular_association? || render_parent_action == :row %>
        if (action_link) action_link.close(true);
      <% else %>
        ActiveScaffold.reload('<%= url_for render_parent_options %>');
      <% end %>
    <% elsif update_refresh_list? %>
      <%= render 'refresh_list', no_history: true %>
    <% else %>
      <% if @record %>
      if (action_link) action_link.close('<%= escape_javascript(render(list_record_view, record: @record)) %>');
      <% else %>
      if (action_link) action_link.close();
      ActiveScaffold.delete_record_row('<%= element_row_id(action: :list, id: params[:id]) %>');
      <% end %>
      <%= render 'update_calculations' %>
    <% end %>
  <% end %>
<% else %>
  ActiveScaffold.replace('<%= form_selector %>', '<%= escape_javascript(render('update_form', xhr: true)) %>');
  ActiveScaffold.scroll_to('<%= form_selector %>', true);
<% end %>
} catch (e) { alert('RJS error:\n\n' + e.toString());}
